﻿using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Domain.BasicData.MaterialManagement.Product_material;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using System.Net.Mime;

namespace B.S.Data.MES.API.Applications.WorkOrderManagement.CommandHandlers
{
    public class GetProduct_materialCommandHandler : IRequestHandler<GetProduct_materialCommand, APIRequst<List<Product_material>>>
    {
        private readonly IBaseRepository<Product_material> _product_materialRepository;
        public GetProduct_materialCommandHandler(IBaseRepository<Product_material> product_materialRepository)
        {
            _product_materialRepository = product_materialRepository;
        }
        public Task<APIRequst<List<Product_material>>> Handle(GetProduct_materialCommand request, CancellationToken cancellationToken)
        {
          var ment=_product_materialRepository.GetAll();
            if(ment==null)
            {
                return Task.FromResult(new APIRequst<List<Product_material>> { 
                
                    Code=RequstCode.失败,
                    Msg=RequstCode.失败.ToString()
                
                });
            }
            return Task.FromResult(new APIRequst<List<Product_material>>
            {
                Data = ment.ToList(),
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()

            });
        }
    }
}
